﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KeMei.Common;
using System.Text;

public partial class Manager_download_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserInfo"] == null)
        {
            Response.Redirect(ConfigHelper.SystemUrl + "Manager/login.aspx", true);

        }
        if (!IsPostBack)
        {
            gridProduct.PageSize = ConfigHelper.pageSize;//设置分页大小

            btnNew.OnClientClick = Win_Edit.GetShowReference("Edit.aspx", "新增下载"); //设置新增按钮，弹出新增窗口

            this.BindList();
        }
    }

    /// <summary>
    /// 取得资料地址
    /// </summary>
    /// <param name="source"></param>
    /// <returns></returns>
    protected string GetFileUrl(string source)
    {
        return ConfigHelper.SystemUrl + source;
    }

   
    /// <summary>
    /// 绑定列表
    /// </summary>
    protected void BindList()
    {
        KeMei.BLL.Download bll = new KeMei.BLL.Download();

        StringBuilder sql = new StringBuilder();
        sql.Append("lmID=3");
        try
        {
            if (!string.IsNullOrEmpty(txtkeyword.Text.Trim()))
            {
                sql.Append(" and TName like '%" + KeMei.Common.PageValidate.InputText(txtkeyword.Text.Trim(), 20) + "%'");
            }

            sql.Append(" order by RecordDate desc");

            gridProduct.DataSource = bll.GetModelList(sql.ToString());
            gridProduct.DataBind();
        }
        catch (Exception ex)
        {

            ExtAspNet.Alert.Show("绑定列表失败：" + ex.Message);
        }
    }

    /// <summary>
    /// 编辑窗口关闭操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Win_Close(object sender, EventArgs e)
    {
        this.BindList();
    }

    /// <summary>
    /// 行操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridProduct_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
    {
        int id = Convert.ToInt32(gridProduct.DataKeys[e.RowIndex][0]);
        string picurl=string.Empty;

        if (e.CommandName == "Delete")
        {
            KeMei.BLL.Download bll = new KeMei.BLL.Download();
            try
            {
                bll.Delete(id);
                if (gridProduct.DataKeys[e.RowIndex][1] != null)
                {
                    picurl = gridProduct.DataKeys[e.RowIndex][1].ToString();
                    FileHelper.DeleteFile(Server.MapPath(ConfigHelper.SystemUrl + picurl));
                }
                BindList();
            }
            catch (Exception ex)
            {
                ExtAspNet.Alert.Show("删除失败：" + ex.Message);
            }
        }
    }

    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridProduct_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
    {
        gridProduct.PageIndex = e.NewPageIndex;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindList();
    }

}